<HTML><HEAD> <!-- ------------------------------------------------ Hello World #6: Saying Hello with another Window ------------------------------------------------ --> <SCRIPT LANGUAGE="JavaScript"><!-- hide from old browsers /* THE JAVASCRIPT COOKBOOK by Erica Sadun, webrx@mindspring.com Copyright (c)1998 by Charles River Media. All Rights Reserved. This applet can only be re-used or modifed by license holders of the JavaScript Cookbook CD-ROM. Credit must be given in the source code and this copyright notice must be maintained. If you do not hold a license to the JavaScript Cookbook, you may NOT duplicate or modify this code for your own use. Use at your own risk. No warranty is given or implied of the suitability of this applet for any specific application. Neither Erica Sadun nor Charles River Media will be held responsible for any unwanted effects due to the use of this applet or any derivative. */ function doHello(msg) { var s1 = "<BODY BGCOLOR=\"ffffff\"><FONT SIZE=6 COLOR=\"770000\"><CENTER>" var s2 = "</CENTER></FONT></BODY>" parent.JSChello.document.open() parent.JSChello.document.write(s1+msg+s2) parent.JSChello.document.close() } <!-- done hiding --></SCRIPT></HEAD> <BODY bgcolor="ffffff" link="0000ff" vlink="770077"> <FONT COLOR="007777"><H1><IMG SRC="../GRAFX/UTENS.JPG" WIDTH=80 HEIGHT=50 ALIGN = LEFT>Communications 106</H1></FONT> <BLOCKQUOTE><FONT COLOR="770000"> After the reader presses the below button, I'll write hello to the above frame. </FONT> <FORM> <INPUT TYPE="button" VALUE=" Say Hello to the Reader " onClick="doHello('Hello World!')" ><p> <INPUT TYPE="button" VALUE=" Say Goodbye to the Reader " onClick="doHello('Goodbye World!')" > </FORM></BLOCKQUOTE> <FONT COLOR="007777"><H2>Discussion</H2></FONT> <FONT SIZE=4> This sixth "hello" program uses <FONT COLOR="770000">document.open()</FONT>, <FONT COLOR="770000">document.write()</FONT> and <FONT COLOR="770000">document.close()</FONT> to reload a frame's contents. <FONT COLOR="770000">Open</FONT> resets the frame so that you can start to load new information with your <FONT COLOR="770000">writes</FONT>. When the writes complete, a <FONT COLOR="770000">close</FONT> instructs the window to stop loading new information.<p> You must designate a particular frame or window to write to, when writing to other than the current frame. In this example, to write to the JSChello frame, it must be given an explicit path. For more details, please read about <a href="../WINDOWS/WINOVR.HTM" target="JCcontent">frames and windows</A>. <h3>Writing to a Frame</h3> <font color="770000" size=3><pre><null >parent.JSChello.document.open()<br><null >parent.JSChello.document.write(s1+msg+s2)<br><null >parent.JSChello.document.close()<br><null ></pre></font> </FONT> <h5>Copyright ©1996 by Charles River Media, All Rights Reserved</h5> </BODY> </HTML>